var a = getApp();

Page({
    data: {
        language: "",
        selected: 0,
        waitPay: [],
        pay: [],
        review: [],
        invalid: [],
        all: [],
        loading: !1,
        allLoaded: !1,
        goload: !1,
        orderType: "",
        ratioDatas: [],
        api: "",
        withdrawal_type: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        name_of_withdrawal: ""
    },
    onLoad: function(a) {
        if (a.type && (this.data.withdrawal_type = a.type), a.orderType && this.setData({
            orderType: a.orderType
        }), this.customizeIncome(), "supplier" == this.data.orderType) a.member_id && this.setData({
            member_id: a.member_id
        }), wx.setNavigationBarTitle({
            title: "我的" + this.data.name_of_withdrawal
        }), this.getSupplierNetData(); else if ("extension" === this.data.orderType) {
            this.data.api = "finance.withdraw.withdraw-log";
            var t = a.selectIndex || 0;
            this.setData({
                selected: t
            }), this.getData(t);
        } else "storeBalance" === this.data.orderType ? (this.data.api = "plugin.store-cashier.frontend.store.balance.award.store", 
        this.getBalanceData(this.selected)) : (this.setData({
            orderType: "store"
        }), this.data.status = "3", this.getNetData(this.data.status));
        "store" == this.data.orderType ? wx.setNavigationBarTitle({
            title: "我的提成"
        }) : wx.setNavigationBarTitle({
            title: "我的" + this.data.name_of_withdrawal
        });
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    getBalanceData: function(t) {
        var e = this, d = a.getNetAddresss(this.data.api);
        a._getNetWork({
            url: d,
            data: {
                status: t
            },
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    console.log(t), wx.setNavigationBarTitle({
                        title: "我的提成"
                    });
                    var d = t.data.list.data, s = [], i = {};
                    i.money = t.data.statistic.today, i.data = "今日", i.name = "data", s.push(i);
                    var o = {};
                    o.money = t.data.statistic.yesterday, o.data = "昨日", o.name = "data", s.push(o);
                    var l = {};
                    l.money = t.data.statistic.week, l.data = "本周", l.name = "data", s.push(l);
                    var n = {};
                    n.money = t.data.statistic.month, n.data = "本月累计提成", n.name = "mounth", s.push(n), 
                    e.setData({
                        ratioDatas: s,
                        allBalance: d,
                        last_page: t.data.list.last_page
                    }), console.log(e.data.ratioDatas);
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getMoreBalanceData: function() {
        var t = this;
        this.setData({
            page: this.data.page + 1
        });
        var e = a.getNetAddresss(this.data.api);
        a._getNetWork({
            url: e,
            data: {
                status: this.data.ind,
                page: this.data.page
            },
            success: function(a) {
                wx.hideLoading({
                    success: function(a) {}
                });
                var e = a.data;
                if (1 == e.result) {
                    console.log(e);
                    var d = e.data.list.data;
                    t.data.allBalance = t.data.allBalance.concat(d), t.setData({
                        allBalance: t.data.allBalance,
                        last_page: e.data.list.last_page
                    }), console.log(t.data.allBalance);
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                wx.hideLoading({
                    success: function(a) {}
                }), console.log(a);
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (this.data.isLoadMore) if (console.log("加载更多"), "supplier" === this.data.orderType) this.getMoreData1(this.data.page, this.data.selected); else if ("extension" === this.data.orderType) this.getMoreData2(this.data.selected); else if ("storeBalance" === this.data.orderType) {
            if (this.data.page >= this.data.last_page) return;
            wx.showLoading({
                title: "加载中"
            }), this.getMoreBalanceData();
        } else "store" === this.data.orderType && this.getMoreData3(this.data.status); else console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    gopresentationDetails: function(a) {
        var t = a.currentTarget.dataset.recordid;
        wx.navigateTo({
            url: "/packageA/member/presentationDetails/presentationDetails?record_id=" + t
        });
    },
    customizeIncome: function() {
        try {
            var a = wx.getStorageSync("mailLanguage");
            if (a) {
                var t = JSON.parse(a);
                this.setData({
                    name_of_withdrawal: t.income.name_of_withdrawal
                });
            }
        } catch (a) {}
    },
    getSupplierNetData: function() {
        0 == this.data.selected ? this.data.api = "plugin.supplier.frontend.withdraw-log.index" : 1 == this.data.selected ? this.data.api = "plugin.supplier.frontend.withdraw-log.applying" : 2 == this.data.selected ? this.data.api = "plugin.supplier.frontend.withdraw-log.pending" : 3 == this.data.selected ? this.data.api = "plugin.supplier.frontend.withdraw-log.already" : 4 == this.data.selected && (this.data.api = "plugin.supplier.frontend.withdraw-log.reject");
        var t = this, e = a.getNetAddresss(t.data.api);
        e += "&member_id=" + t.data.member_id, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var d = e.data;
                    t.setData({
                        total_page: d.total,
                        allLoaded: !1
                    }), t.data.total_page || t.setData({
                        total_page: 0
                    }), 0 == t.data.selected ? t.setData({
                        all: d.data
                    }) : 1 == t.data.selected ? t.setData({
                        review: d.data
                    }) : 2 == t.data.selected ? t.setData({
                        waitPay: d.data
                    }) : 3 == t.data.selected ? t.setData({
                        pay: d.data
                    }) : 4 == t.data.selected && t.setData({
                        invalid: d.data
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getData: function(t) {
        var e = "";
        0 == t ? e = "" : 1 == t ? e = "0" : 2 == t ? e = "1" : 3 == t ? e = "2" : 4 == t && (e = "-1");
        var d = this, s = a.getNetAddresss("finance.withdraw.withdraw-log");
        d.data.isLoadMore = !1, d.data.page = 1, a._getNetWork({
            url: s,
            data: {
                status: e
            },
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    d.data.allLoaded = !1, d.data.isLoadMore = !0, d.data.total_page = t.data.last_page, 
                    d.data.total_page || (d.data.total_page = 0);
                    var e = t.data.data;
                    0 == d.data.selected ? d.setData({
                        all: e
                    }) : 1 == d.data.selected ? d.setData({
                        review: e
                    }) : 2 == d.data.selected ? d.setData({
                        waitPay: e
                    }) : 3 == d.data.selected ? d.setData({
                        pay: e
                    }) : 4 == d.data.selected && d.setData({
                        invalid: e
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getNetData: function(t) {
        var e = this, d = a.getNetAddresss("finance.withdraw.withdraw-list");
        e.data.isLoadMore = !1, e.data.page = 1, a._getNetWork({
            url: d,
            data: {
                status: t,
                withdrawal_type: this.data.withdrawal_type
            },
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    e.data.allLoaded = !1, e.data.isLoadMore = !0, e.data.total_page = t.data.last_page, 
                    e.data.total_page || (e.data.total_page = 0);
                    var d = [], s = {};
                    s.money = t.data.today, s.data = "今日", s.name = "data", d.push(s);
                    var i = {};
                    i.money = t.data.yesterday, i.data = "昨日", i.name = "data", d.push(i);
                    var o = {};
                    o.money = t.data.lastweek, o.data = "本周", o.name = "data", d.push(o);
                    var l = {};
                    l.money = t.data.thismonth, l.data = "本月累计提成", l.name = "mounth", d.push(l), e.setData({
                        ratioDatas: d
                    });
                    var n = t.data.data;
                    0 == e.data.selected ? e.setData({
                        all: n
                    }) : 1 == e.data.selected ? e.setData({
                        review: n
                    }) : 2 == e.data.selected ? e.setData({
                        waitPay: n
                    }) : 3 == e.data.selected && e.setData({
                        invalid: n
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    swichTabTItem: function(a) {
        var t = a.detail.index;
        this.setData({
            selected: t
        }), "supplier" === this.data.orderType ? this.getSupplierNetData() : "extension" === this.data.orderType ? this.getData(this.data.selected) : "storeBalance" == this.data.orderType ? (this.setData({
            allBalance: [],
            page: 1,
            ind: a.detail.name
        }), this.getBalanceData(this.data.ind)) : "store" === this.data.orderType && (0 == a.detail.index ? this.data.status = "3" : 1 == a.detail.index ? this.data.status = "0" : 2 == a.detail.index ? this.data.status = "1" : 3 == a.detail.index && (this.data.status = "-1"), 
        this.getNetData(this.data.status));
    },
    getMoreData1: function(t, e) {
        if (this.data.page != this.data.total_page) {
            if (this.data.page >= this.data.total_page) return this.data.loading = !0, void (this.data.allLoaded = !0);
            this.data.page = this.data.page + 1;
            var d = this, s = a.getNetAddresss(d.data.api);
            a._getNetWork({
                url: s,
                data: {
                    page: d.data.page,
                    member_id: d.data.member_id
                },
                success: function(a) {
                    var t = a.data;
                    if (1 == t.result) {
                        var s = t.data.data;
                        d.data.loading = !1, d.data.allLoaded = !1, 0 == e ? d.setData({
                            all: d.data.all.concat(s)
                        }) : 1 == e ? d.setData({
                            review: d.data.review.concat(s)
                        }) : 2 == e ? d.setData({
                            waitPay: d.data.waitPay.concat(s)
                        }) : 3 == e ? d.setData({
                            pay: d.data.pay.concat(s)
                        }) : 4 == e && d.setData({
                            invalid: d.data.invalid.concat(s)
                        });
                    } else d.data.page = d.data.page - 1, d.data.loading = !0, d.data.allLoaded = !0, 
                    d.data.isLoadMore = !1;
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    getMoreData2: function(t) {
        var e = "";
        0 == t ? e = "" : 1 == t ? e = "0" : 2 == t ? e = "1" : 3 == t ? e = "2" : 4 == t && (e = "-1");
        var d = this, s = a.getNetAddresss("finance.withdraw.withdraw-log");
        d.isLoadMore = !1, this.data.page >= this.data.total_page || (this.data.page = this.data.page + 1, 
        a._getNetWork({
            url: s,
            data: {
                status: e,
                page: d.data.page
            },
            success: function(a) {
                var t = a.data;
                if (d.data.isLoadMore = !0, d.data.loading = !1, d.data.allLoaded = !1, 1 == t.result) {
                    var e = t.data.data;
                    0 == d.data.selected ? d.setData({
                        all: d.all.concat(e)
                    }) : 1 == d.data.selected ? d.setData({
                        review: d.review.concat(e)
                    }) : 2 == d.data.selected ? d.setData({
                        waitPay: d.waitPay.concat(e)
                    }) : 3 == d.data.selected ? d.setData({
                        pay: d.pay.concat(e)
                    }) : 4 == d.data.selected && d.setData({
                        invalid: d.invalid.concat(e)
                    });
                } else d.data.page = d.data.page - 1, d.data.isLoadMore = !1, d.data.loading = !0, 
                d.data.allLoaded = !0, d.data.isLoadMore = !1;
            },
            fail: function(a) {
                console.log(a);
            }
        }));
    },
    getMoreData3: function(t) {
        var e = this, d = a.getNetAddresss("finance.withdraw.withdraw-log");
        e.isLoadMore = !1, this.data.page >= this.data.total_page || (this.data.page = this.data.page + 1, 
        a._getNetWork({
            url: d,
            data: {
                status: e.data.status,
                withdrawal_type: e.data.withdrawal_type,
                page: e.data.page
            },
            success: function(a) {
                var t = a.data;
                if (e.data.isLoadMore = !0, e.data.loading = !1, e.data.allLoaded = !1, 1 == t.result) {
                    var d = t.data.data;
                    0 == e.data.selected ? e.setData({
                        all: e.all.concat(d)
                    }) : 1 == e.data.selected ? e.setData({
                        review: e.review.concat(d)
                    }) : 2 == e.data.selected ? e.setData({
                        waitPay: e.waitPay.concat(d)
                    }) : 3 == e.data.selected && e.setData({
                        invalid: e.invalid.concat(d)
                    });
                } else e.data.page = e.data.page - 1, e.data.isLoadMore = !1, e.data.loading = !0, 
                e.data.allLoaded = !0, e.data.isLoadMore = !1;
            },
            fail: function(a) {
                console.log(a);
            }
        }));
    }
});